//
//  MCProgressTableCell.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/18.
//

import UIKit

class MCProgressTableCell: UITableViewCell {

    @IBOutlet weak var stateButton: UIButton!
    @IBOutlet weak var subView: UIView!
    
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var stateLabel: UILabel!
    
    @IBOutlet weak var planNameLabel: UILabel!
    
    @IBOutlet weak var levelLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.selectionStyle = .none

//        subView.layer.backgroundColor = UIColor(red: 0.969, green: 0.969, blue: 0.976, alpha: 1).cgColor
//        subView.layer.cornerRadius = 4
//        subView.layer.borderWidth = 1
//        subView.layer.borderColor = UIColor(red: 0.208, green: 0.871, blue: 0.58, alpha: 1).cgColor
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    
    func configCell(model: HomeTodayListModel?) {
        
        guard let model = model else { return }
        planNameLabel.text = model.planName
        levelLabel.text = "L\(String(describing: model.planLevel ?? 0))"
        if let conflict = model.isTimeConflict, conflict > 0 {
            stateLabel.text = "时间冲突"
            stateLabel.textColor = UIColor.pg_color(withHexString: "DE3535")
            stateButton.setImage(UIImage(named: "home_plan_normal"), for: .normal)

        } else {
            stateLabel.text = model.getPlanStatus().toString
            let status = model.getPlanStatus()
            switch status {
            case .idle, .inProgress:
                stateLabel.textColor = UIColor.pg_color(withHexString: "109B5E")
            case .complete, .timeout:
                stateLabel.textColor = UIColor.pg_color(withHexString: "DE3535")
            }
            if status == .complete {
                stateButton.setImage(UIImage(named: "home_plan_selected"), for: .normal)
            } else {
                stateButton.setImage(UIImage(named: "home_plan_normal"), for: .normal)

            }
        }
        
    }
    
}
